package com.health.mapp.interImpl;

import com.health.db.model.RegisterOrderAction;
import com.health.db.model.UserLIST;
import com.health.db.service.order.IRegisterOrderActionService;
import com.health.db.service.order.IRegisterOrderService;
import com.health.db.service.user.IUserLISTService;
import com.health.mapp.utils.Constant;



/**
 * 线程启动
 * 
 * @author HiRoad
 * 
 */

public class DelayUpdateRegisterOrderAction extends Thread {

	/**
	 * 线程启动
	 * 
	 * @author HiRoad
	 * 
	 */
		private long orderId;
		private int type;
		private long userId;
		IUserLISTService uService;
		IRegisterOrderActionService rService;

		public DelayUpdateRegisterOrderAction(long orderId, 
				int type,
				long userId,
				IUserLISTService uService, 
				IRegisterOrderActionService rService) {
			super();
			this.orderId = orderId;
			this.type = type;
			this.userId = userId;
			this.uService = uService;
			this.rService = rService;
		}

		
		public DelayUpdateRegisterOrderAction(long orderId, 
				int type,
				long userId,
				IUserLISTService uService, 
				IRegisterOrderActionService rService,int freeType) {
			super();
			this.orderId = orderId;
			this.type = type;
			this.userId = userId;
			this.uService = uService;
			this.rService = rService;
		}
		
		public void run() {
			delayUpdateOrder(orderId, type, userId, uService, rService);
		}
	/**
	 * 延时处理更新user表
	 */
	private void delayUpdateOrder(long orderId, int type,
			long userId,
			IUserLISTService uService,
			IRegisterOrderActionService rService) {

		// 查看用户表相关信息
		Long docId = userId;
		UserLIST userLIST = uService.selectByUserId(docId);
		RegisterOrderAction registerOrderAction = new RegisterOrderAction();
		registerOrderAction.setRegisterid(Long.valueOf(orderId));
		registerOrderAction.setOperatorid(docId);
		registerOrderAction.setCreateUserid(docId);
		registerOrderAction.setOperatorName(userLIST.getUserNo() + "|"+ userLIST.getUserName());
		
		if (type==Constant.CONSTANTS_ORDER_ACTION_ID_1) {
			//草稿->待支付
			registerOrderAction.setActionName(Constant.CONSTANTS_ORDER_ACTION_DES_1);
			registerOrderAction.setDoendStatus(Constant.CONSTANTS_ORDER_RUNSTATUS_DES_1);
		} else if (type == Constant.CONSTANTS_ORDER_ACTION_ID_2) {
			//支付->待就诊
			registerOrderAction.setActionName(Constant.CONSTANTS_ORDER_ACTION_DES_2);
			registerOrderAction.setDoendStatus(Constant.CONSTANTS_ORDER_RUNSTATUS_DES_2);
		} else if (type == Constant.CONSTANTS_ORDER_ACTION_ID_3) {
			//接诊->就诊中
			registerOrderAction.setActionName(Constant.CONSTANTS_ORDER_ACTION_DES_3);
			registerOrderAction.setDoendStatus(Constant.CONSTANTS_ORDER_RUNSTATUS_DES_3);
		} else if (type == Constant.CONSTANTS_ORDER_ACTION_ID_4) {
			//结诊->待评价
			registerOrderAction.setActionName(Constant.CONSTANTS_ORDER_ACTION_DES_4);
			registerOrderAction.setDoendStatus(Constant.CONSTANTS_ORDER_RUNSTATUS_DES_4);
		} else if (type == Constant.CONSTANTS_ORDER_ACTION_ID_5) {
			//评价->已完成
			registerOrderAction.setActionName(Constant.CONSTANTS_ORDER_ACTION_DES_5);
			registerOrderAction.setDoendStatus(Constant.CONSTANTS_ORDER_RUNSTATUS_DES_5);
		} else if (type == Constant.CONSTANTS_ORDER_ACTION_ID_6) {
			//拒单->已关闭
			registerOrderAction.setActionName(Constant.CONSTANTS_ORDER_ACTION_DES_6);
			registerOrderAction.setDoendStatus(Constant.CONSTANTS_ORDER_RUNSTATUS_DES_6);
		}else if (type == Constant.CONSTANTS_ORDER_ACTION_ID_9) {
			//免费->待就诊
			registerOrderAction.setActionName(Constant.CONSTANTS_ORDER_ACTION_DES_9);
			registerOrderAction.setDoendStatus(Constant.CONSTANTS_ORDER_RUNSTATUS_DES_2);
		 }else if (type == Constant.CONSTANTS_ORDER_ACTION_ID_7) {
				//退款->退款中
				registerOrderAction.setActionName(Constant.CONSTANTS_ORDER_ACTION_DES_7);
				registerOrderAction.setDoendStatus(Constant.CONSTANTS_ORDER_RUNSTATUS_DES_7);
		 
		}else{
			return;
		}
		
		rService.insertOrderAction(registerOrderAction);
	}
}